package 分类.链表;

public class 删除链表的倒数第N个结点 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode slow,fast;

        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        slow=fast=dummy;
        for (int i=0;i<n+1;i++){
            fast=fast.next;
        }
        while (fast!=null){
            slow=slow.next;
            fast=fast.next;
        }
        slow.next=slow.next.next;
        return dummy.next;
    }

}
